package com.kaifamiao.www.demo.do0803;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;

public class Demo01 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //当前默认编码UTF-8
        System.out.println(Charset.defaultCharset());

        Charset.forName("utf-8");
        byte[] bytes = "智者谋其利，愚者争虚名".getBytes("GBK");
        System.out.println(Arrays.toString(bytes));
        System.out.println(bytes.length);
        byte[] bytes1 = Arrays.copyOf(bytes,50);
        String str = new String(bytes1,0,22,"GBK");
        System.out.println(str);
        //出现乱码，是因为编码和解码使用的字符集不同造成的
        char[] chs = {'世', '界', '上', '只', '有', '一', '个', '中', '国'};
        String s = new String(chs);
        System.out.println(s);


        String sc = String.join(",","ab","bc","cd","de");
        System.out.println(sc);
    }
}
